cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : bitset : operator[]
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
bitset
bitset::bitset
bitset operators
member functions:
· bitset::any
· bitset::count
· bitset::flip
· bitset::none
· bitset::operator[]
· bitset::reset
· bitset::set
· bitset::size
· bitset::test
· bitset::to_string
· bitset::to_ulong

-

bitset::operator[] public member function
     bool operator[] ( size_t pos ) const;
reference operator[] ( size_t pos );

Access bit

The function returns the value (or a reference) to the bit at position pos.

With this operator, no range check is performed. Use bitset::test to read the value with bitset bounds checked.

Parameters

pos
Order position of the bit whose value is accessed.
Order positions are counted from the rightmost bit, which is order position 0.
size_t is an unsigned integral type.

Return value

*this

Example

// bitset::operator[]
#include <iostream>
#include <bitset>
using namespace std;

int main ()
{
  bitset<4> mybits;

  mybits[1]=1;             // 0010
  mybits[2]=mybits[1];     // 0110

  cout << "mybits: " << mybits << endl; 

  return 0;
}

See also

bitset::bitset Construct bitset (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us